from base.port_item import PortItem
# from base_module import BaseModule
from base.cell import Cell

class RAMB36E1(Cell):
    
    def __init__(self,name) -> None:
        super().__init__(name)
        self.type = "RAMB36E1"

        self.all_ports["ADDRARDADDR"] = PortItem(width=16,name="ADDRARDADDR",parent=self)
        self.all_ports["ADDRBWRADDR"] = PortItem(width=16,name="ADDRBWRADDR",parent=self)
        self.all_ports["DIADI"] = PortItem(width=32,name="DIADI",parent=self)
        self.all_ports["DIBDI"] = PortItem(width=32,name="DIBDI",parent=self)
        self.all_ports["DIPADIP"] = PortItem(width=4,name="DIPADIP",parent=self)
        self.all_ports["DIPBDIP"] = PortItem(width=4,name="DIPBDIP",parent=self)
        self.all_ports["WEA"] = PortItem(width=4,name="WEA",parent=self)
        self.all_ports["WEBWE"] = PortItem(width=4,name="WEBWE",parent=self)
        self.all_ports["CASCADEINA"] = PortItem(name="CASCADEINA",parent=self)
        self.all_ports["CASCADEINB"] = PortItem(name="CASCADEINB",parent=self)
        self.all_ports["CLKARDCLK"] = PortItem(name="CLKARDCLK",parent=self)
        self.all_ports["CLKBWRCLK"] = PortItem(name="CLKBWRCLK",parent=self)
        self.all_ports["ENARDEN"] = PortItem(name="ENARDEN",parent=self)
        self.all_ports["ENBWREN"] = PortItem(name="ENBWREN",parent=self)
        self.all_ports["INJECTDBITERR"] = PortItem(name="INJECTDBITERR",parent=self)
        self.all_ports["INJECTDSITERR"] = PortItem(name="INJECTDSITERR",parent=self)
        self.all_ports["REGCEAREGCE"] = PortItem(name="REGCEAREGCE",parent=self)
        self.all_ports["REGCEB"] = PortItem(name="REGCEB",parent=self)
        self.all_ports["RSTRAMARSTRAM"] = PortItem(name="RSTRAMARSTRAM",parent=self)
        self.all_ports["RSTRAMB"] = PortItem(name="RSTRAMB",parent=self)
        self.all_ports["RSTREGARSTREG"] = PortItem(name="RSTREGARSTREG",parent=self)
        self.all_ports["RSTREGB"] = PortItem(name="RSTREGB",parent=self)
        self.all_ports["DOADO"] = PortItem(name="DOADO",width=32,type="output",parent=self)
        self.all_ports["DOBDO"] = PortItem(name="DOBDO",width=32,type="output",parent=self)
        self.all_ports["DOPADOP"] = PortItem(name="DOPADOP",width=4,type="output",parent=self)
        self.all_ports["DOPBDOP"] = PortItem(name="DOPBDOP",width=4,type="output",parent=self)
        self.all_ports["ECCPARITY"] = PortItem(name="ECCPARITY",width=8,type="output",parent=self)
        self.all_ports["RDADDRECC"] = PortItem(name="RDADDRECC",width=9,type="output",parent=self)
        self.all_ports["CASCADEOUTA"] = PortItem(name="CASCADEOUTA",type="output",parent=self)
        self.all_ports["CASCADEOUTB"] = PortItem(name="CASCADEOUTB",type="output",parent=self)
        self.all_ports["DBITERR"] = PortItem(name="DBITERR",type="output",parent=self)
        self.all_ports["SBITERR"] = PortItem(name="SBITERR",type="output",parent=self)

        self.init_parameters()
        
        pass
    
    
    def init_parameters(self):
        self.set_ram_mode()
        self.set_write_mode_a()
        self.set_read_width_a()

    def set_ram_mode(self,ram_mode = "TDP"):
        key = "RAM_MODE"
        self.used_parameter[key] = ram_mode
    def set_write_mode_a(self, write_mode_a = "WRITE_FIRST"):
        key = "WRITE_MODE_A"
        self.used_parameter[key] = write_mode_a
    def set_read_width_a(self,width=1):
        key = "READ_WIDTH_A"
        binary_string = bin(width)[2:]
        padded_binary_string = binary_string.zfill(32)
        self.used_parameter[key] = padded_binary_string
    def set_parameter(self,name,value):
        self.used_parameter[name] = value

    


    def set_init(self,data):
        pass